package org.jeecg.modules.qyxx.service.impl;


import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import groovy.transform.AutoFinal;
import org.jeecg.modules.qyxx.entity.BgFpHzNdSygys;
import org.jeecg.modules.qyxx.entity.resp.BgFpHzNdSygysVo;
import org.jeecg.modules.qyxx.mapper.BgFpHzNdSygysMapper;
import org.jeecg.modules.qyxx.service.IBgFpHzNdSygysService;
import org.jeecg.modules.qyxx.service.IBgSjmkjgOrderService;
import org.jeecg.modules.qyxx.service.IBgSwzbjcOrderService;
import org.jeecg.modules.qyxx.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description: 上游供应商汇总数据
 * @Author: ZJJ
 * @Date: 2021-06-09
 * @Version: V1.0
 */
// // @DS("multi-datasource1")申报
@Service
public class BgFpHzNdSygysServiceImpl extends MppServiceImpl<BgFpHzNdSygysMapper, BgFpHzNdSygys> implements IBgFpHzNdSygysService {
    @Autowired
    private IBgSjmkjgOrderService bgSjmkjgOrderService;

    @Override
    public List<BgFpHzNdSygysVo> sygyssjhz(String djxh, List<String> tjnds, Date jssj) {
        // List<BgFpHzNdSygysVo> sygyssjhz = baseMapper.sygyssjhz(djxh, tjnds);
        List<BgFpHzNdSygysVo> sygyssjhz = baseMapper.sygyssjhz(djxh,String.join(",",tjnds));
        // String year = bgSjmkjgOrderService.getNewByDjxh(djxh);
        DateUtils utils = DateUtils.getInstance();
        String year = utils.getYearToStr(jssj);
        for (BgFpHzNdSygysVo bgFpHzNdSygysVo : sygyssjhz) {
            if (bgFpHzNdSygysVo.getGysFpje() != null) {
                bgFpHzNdSygysVo.setGysFpje(bgFpHzNdSygysVo.getGysFpje().divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
            }
            if (bgFpHzNdSygysVo.getGysFpse() != null) {
                bgFpHzNdSygysVo.setGysFpse(bgFpHzNdSygysVo.getGysFpse().divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
            }
            bgFpHzNdSygysVo.setTsYear(bgFpHzNdSygysVo.getTjnd()+ "年");
            if (year.equals(bgFpHzNdSygysVo.getTjnd())) {
                // String month = bgSjmkjgOrderService.getNewMonthByDjxh(djxh);
                String month = utils.getMonthToStr(jssj);
                String newMonth = month.substring(month.length() - 2);
                bgFpHzNdSygysVo.setTjnd(year + "年(" + newMonth + "月)");
            }else {
                bgFpHzNdSygysVo.setTjnd(bgFpHzNdSygysVo.getTjnd() + "年");
            }
        }
        return sygyssjhz;
    }

    @Override
    public BgFpHzNdSygys getByDjxhAndTjnd(String djxh, String tjnd) {
        LambdaQueryWrapper<BgFpHzNdSygys> wrapper = Wrappers.lambdaQuery(BgFpHzNdSygys.class);
        wrapper.eq(BgFpHzNdSygys::getDjxh,djxh).eq(BgFpHzNdSygys::getTjnd,tjnd);
        return getOne(wrapper);
    }
}
